home *** CD-ROM | disk | FTP | other *** search
- Newsgroups: comp.lang.c,comp.unix.programmer
- Path: bcc.ac.uk!news
- From: Bill Zissimopoulos <B.Zissimopoulos@cs.ucl.ac.uk>
- Subject: Re: Q: '\n' character
- Message-ID: <3169994D.665ACF69@cs.ucl.ac.uk>
- Date: Mon, 8 Apr 1996 22:55:09 GMT
- Content-Transfer-Encoding: 7bit
- Content-Type: text/plain; charset=us-ascii
- References: <31616F63.481D@lava.weeg.uiowa.edu> <4jtddt$eu7@masala.cc.uh.edu> <DpBuF6.83C@ukpsshp1.serigate.philips.nl>
- Mime-Version: 1.0
- X-Mailer: Mozilla 2.01 (X11; I; Linux 1.2.13 i586)
- Organization: University College London
-
- Stephen Baynes wrote:
- >
- > Spasmo (cosc19z5@Bayou.UH.EDU) wrote:
- > : Artur Wojdat (awojdat@lava.weeg.uiowa.edu) wrote:
- > : : Hello everybody,
- > : : Is there a function or some sort of way that I could remove '\n'
- > : : charecter form the end of the string. I'm reading from two files, want to
- > : Dunno if there are any functions available, but what I always do
- > : is just overwrite the '\n' with a '\0', which does the job nicely.
- >
- > : For example, let's say that the string that holds the data is called
- > : buf. To get rid of the '\n' you'd merely do the following:
- >
- > : buf[strlen(buf) - 1] = '\0';
- >
- > : And that takes care of that.
- >
- > Thats the best way, but do check that the character you are about to overwrite
- > is a newline. There are two occasions when fgets stops without reading a
- > newline, first if it has filled your buffer (because you have a very long line
- > in the file), second if there is no newline at the end of the last line of the
- > file.
-
- Which makes this the worst way for the exact reasons that you give.
-
- --
- Bill Zissimopoulos <B.Zissimopoulos@cs.ucl.ac.uk>
- http://www-dept.cs.ucl.ac.uk/students/B.Zissimopoulos/
-
-